﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
namespace Gronia.WPF.Controls
{
    public partial class AlignedWrapPanel : WrapPanel
    {
        public HorizontalAlignment HorizontalContentAlignment
        {
            get { return (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty); }
            set { SetValue(HorizontalContentAlignmentProperty, value); }
        }

        public VerticalAlignment VerticalContentAlignment
        {
            get { return (VerticalAlignment)GetValue(VerticalContentAlignmentProperty); }
            set { SetValue(VerticalContentAlignmentProperty, value); }
        }

        public ChildOrder ChildOrder
        {
            get { return (ChildOrder)GetValue(ChildOrderProperty); }
            set { SetValue(ChildOrderProperty, value); }
        }

        public static readonly DependencyProperty HorizontalContentAlignmentProperty = DependencyProperty.Register("HorizontalContentAlignment", typeof(HorizontalAlignment), typeof(AlignedWrapPanel), new FrameworkPropertyMetadata(HorizontalAlignment.Left, FrameworkPropertyMetadataOptions.AffectsMeasure), new ValidateValueCallback(IsHorizontalContentAlignmentValid));
        public static readonly DependencyProperty VerticalContentAlignmentProperty = DependencyProperty.Register("VerticalContentAlignment", typeof(VerticalAlignment), typeof(AlignedWrapPanel), new FrameworkPropertyMetadata(VerticalAlignment.Top, FrameworkPropertyMetadataOptions.AffectsMeasure), new ValidateValueCallback(IsVerticalContentAlignmentValid));
        public static readonly DependencyProperty ChildOrderProperty = DependencyProperty.Register("ChildOrder", typeof(ChildOrder), typeof(AlignedWrapPanel), new FrameworkPropertyMetadata(ChildOrder.Normal, FrameworkPropertyMetadataOptions.AffectsMeasure));

        private static bool IsHorizontalContentAlignmentValid(object o)
        {
            HorizontalAlignment align = (HorizontalAlignment)o;
            return align == HorizontalAlignment.Left || align == HorizontalAlignment.Right;
        }

        private static bool IsVerticalContentAlignmentValid(object o)
        {
            VerticalAlignment align = (VerticalAlignment)o;
            return align == VerticalAlignment.Top || align == VerticalAlignment.Bottom;
        }
    }
}